package com.redmoon.dingding.service.auth;


import com.cloudweb.oa.api.IDdService;
import com.cloudweb.oa.utils.SpringUtil;
import com.cloudwebsoft.framework.util.LogUtil;
import com.dingtalk.api.DefaultDingTalkClient;
import com.dingtalk.api.request.OapiGettokenRequest;
import com.dingtalk.api.response.OapiGettokenResponse;
import com.dingtalk.oapi.lib.aes.DingTalkJsApiSingnature;
import com.redmoon.dingding.Config;
import com.redmoon.dingding.domain.AccessTokenDto;
import com.redmoon.dingding.domain.JsapiTicketDto;
import com.redmoon.dingding.util.HttpHelper;
import com.redmoon.dingding.util.DdException;
import com.redmoon.oa.sys.DebugUtil;
import com.redmoon.oa.system.OaSysVerMgr;

import javax.servlet.http.HttpServletRequest;
import java.net.URLDecoder;
import java.util.Date;

public class AuthService {
    //1小时50分钟
    public static final long cacheTime = 1000 * 60 * 55 * 2;

    /**
     * 获得accessToken
     *
     * @return
     */
    public static String getAccessToken() {
        IDdService ddService = SpringUtil.getBean(IDdService.class);
        return ddService.getAccessToken();
    }

    /**
     * 计算当前请求的jsapi的签名数据<br/>
     * <p>
     * 如果签名数据是通过ajax异步请求的话，签名计算中的url必须是给用户展示页面的url
     *
     * @param request
     * @return
     */
    public static String getConfig(HttpServletRequest request) {
        IDdService ddService = SpringUtil.getBean(IDdService.class);
        return ddService.getConfig(request);
    }
}
